﻿using IQIGame.Onigao.Framework.Serialization;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_PackageActionCondition : SkillEffective
    {
        protected override ISerializeCustomPOD OnActionExecute(SkillEffectiveData data, SkillActionNode action, Unit target, ref SkillEffectiveContext context, int effectiveIndex)
        {
            if (action.customConfig is SkillEffectiveAction_PackageActionCondition_ConfigData rConfig)
            {
                var rAttacker = context.skill.executer;
                var bCondition = rConfig.condition?.GetValue(rAttacker, target, context) ?? true;
                if (bCondition)
                {
                    return SkillEffective_Package.PackageOnExecute(rConfig.trueActions, target, ref context, effectiveIndex);
                }
                else
                {
                    return SkillEffective_Package.PackageOnExecute(rConfig.falseActions, target, ref context, effectiveIndex);
                }
            }
            return null;
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            var rConfig = config as SkillEffectiveAction_PackageActionCondition_ConfigData;
            return $"条件执行";
        }
#endif
    }
}